#include <iostream>
#include "socketE.h"
#include "connector.h"
#include "Logger.h"
#include "singleton.h"
#include "epollE.h"
#include "server.h"
#include "threadPool.h"
#include "dispatcher.h"
#include "signal.h"
#include "sys/signalfd.h"
#include "Json.h"

using namespace easyWebServer;
using namespace std;


int main(int argc, char* argv[]) {

    if(argc != 2)
    {
        std::cout << "can not find configs" << std::endl;
        Singleton<yazi::json::Json>::getInstance().parseFromFile("/home/dxy/code/easyWebServer/config/config.conf");
    }
    else
    {
        Singleton<yazi::json::Json>::getInstance().parseFromFile(argv[1]);
    }

    // cout << Singleton<yazi::json::Json>::getInstance().str() << endl;
    // cout << Singleton<yazi::json::Json>::getInstance()["threadPoolNumber"].asInt() << endl;

    chdir(Singleton<yazi::json::Json>::getInstance()["root"].asString().c_str());
    
    Logger::instance()->open("./test.log");
    Logger::instance()->level(Logger::Level::INFO);
    Logger::instance()->isTermial(false);
    Logger::instance()->max(1024 * 100);

    string ip = Singleton<yazi::json::Json>::getInstance()["host"].asString();
    int port = Singleton<yazi::json::Json>::getInstance()["port"].asInt();

    Server server(ip, port);
    server.start();
}
